home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / TouchMe 1.1.1.sit / touchMe 1.11 Folder / CW9 PP source / source / Common / UDateTime.cp < prev    next >
Text File  |  1996-08-08  |  4KB  |  159 lines

  1. // ==================================================
  2. //    UDateTime.cp
  3. //    Copyright (C) 1994-96 Mizutori Tetsuya, March 9 1994, July 4 1996.
  4. // ==================================================
  5. //    All documents are pretty-printed in Geneva 10-point font.
  6.  
  7. #include <TextUtils.h>
  8. #include <Script.h>
  9. #include <IntlResources.h>
  10. #include <OSUtils.h>
  11.  
  12. #include <UMemoryMgr.h>
  13. #include <UDebugging.h>
  14.  
  15. #include "UDateTime.h"
  16.  
  17. #define longDateTimeHi( a )    (((LongDateCvt *) &(a))->hl.lHigh)
  18. #define longDateTimeLo( a )    (((LongDateCvt *) &(a))->hl.lLow)
  19.  
  20.  
  21. #define    kWantSeconds            true
  22. #define    k_intl_NumericFormat    0
  23. #define    k_intl_LongDateFormat    1
  24.  
  25.  
  26. // --------------------------------------------------
  27. //        ・ SecondsToDateTimeString
  28. // --------------------------------------------------
  29.  
  30. void
  31. UDateTime::SecondsToDateTimeString( 
  32.     const unsigned long    inSeconds,
  33.     Str255            outDateString,
  34.     Str255            outTimeString )
  35. {
  36.     LongDateRec    theDateTime;
  37.  
  38.     SecondsToDateTime( inSeconds, theDateTime );
  39.  
  40.     DateTimeToString( theDateTime, outDateString, outTimeString );
  41. }
  42.  
  43.  
  44. // --------------------------------------------------
  45. //        ・ DateTimeStringToSeconds
  46. // --------------------------------------------------
  47.  
  48. void
  49. UDateTime::DateTimeStringToSeconds(
  50.     const Str255    inDateString,
  51.     const Str255    inTimeString,
  52.     unsigned long &    outSeconds )
  53. {
  54.     LongDateRec    theDateTime;
  55.  
  56.     StringToDateTime( inDateString, inTimeString, theDateTime );
  57.  
  58.     DateTimeToSeconds( theDateTime, outSeconds );
  59. }
  60.  
  61.  
  62. // --------------------------------------------------
  63. //        ・ SecondsToDateTime
  64. // --------------------------------------------------
  65.  
  66. void
  67. UDateTime::SecondsToDateTime(
  68.     const unsigned long    inSeconds,
  69.     LongDateRec &        outDateTime )
  70. {
  71.     LongDateTime    theDateTimeSecs;
  72.  
  73.     longDateTimeHi( theDateTimeSecs ) = 0;
  74.     longDateTimeLo( theDateTimeSecs ) = inSeconds;
  75.  
  76.     ::LongSecondsToDate( &theDateTimeSecs, &outDateTime );
  77. }
  78.  
  79.  
  80. // --------------------------------------------------
  81. //        ・ DateTimeToSeconds
  82. // --------------------------------------------------
  83.  
  84. void
  85. UDateTime::DateTimeToSeconds(
  86.     const LongDateRec &    inDateTime,
  87.     unsigned long &        outSeconds )
  88. {
  89.     LongDateTime    theDateTimeSecs;
  90.  
  91.     LongDateToSeconds( &inDateTime, &theDateTimeSecs );
  92.  
  93.     outSeconds = longDateTimeLo( theDateTimeSecs );
  94. }
  95.  
  96.  
  97. // --------------------------------------------------
  98. //        ・ DateTimeToString
  99. // --------------------------------------------------
  100.  
  101. void
  102. UDateTime::DateTimeToString(
  103.     const LongDateRec &    inDateTime,
  104.     Str255            outDateString,
  105.     Str255            outTimeString )
  106. {
  107.     LongDateTime    theDateTimeSecs;
  108.     LongDateToSeconds( &inDateTime, &theDateTimeSecs );
  109.  
  110.     Handle    intlH;
  111.     Size        theSize;
  112.     intlH = ::GetIntlResource( k_intl_NumericFormat );    // as 'Intl0Rec'
  113.     theSize = ::GetHandleSize( intlH );
  114.  
  115.     StClearHandleBlock    theIntlH( theSize, true );
  116.     ::BlockMoveData( *intlH, *theIntlH, theSize );
  117.  
  118. //    ((Intl0Ptr)*theIntlH)->dateOrder = mdy;            // m/d/y order
  119. //    ((Intl0Ptr)*theIntlH)->shrtDateFmt = century;        // include century
  120. //    ((Intl0Ptr)*theIntlH)->shrtDateFmt |= mntLdingZ;    // lead 0 for month
  121. //    ((Intl0Ptr)*theIntlH)->shrtDateFmt |= dayLdingZ;    // lead 0 for day
  122. //    ((Intl0Ptr)*theIntlH)->shrtDateFmt &= ~century;    // suppress century
  123. //    ((Intl0Ptr)*theIntlH)->dateSep = '/';                // date separator
  124.  
  125.     ::LongDateString( &theDateTimeSecs, shortDate, outDateString, theIntlH );
  126.  
  127.     ((Intl0Ptr)*theIntlH)->timeCycle = timeCycle24;    // or; timeCycleZero, timeCycle12
  128.     ((Intl0Ptr)*theIntlH)->timeFmt |= secLeadingZ | minLeadingZ | hrLeadingZ;
  129. //    ((Intl0Ptr)*theIntlH)->timeSep = ':';                // time separator
  130.  
  131.     ::LongTimeString( &theDateTimeSecs, kWantSeconds, outTimeString, theIntlH );
  132. }
  133.  
  134.  
  135. // --------------------------------------------------
  136. //        ・ StringToDateTime
  137. // --------------------------------------------------
  138.  
  139. void
  140. UDateTime::StringToDateTime(
  141.     const Str255    inDateString,
  142.     const Str255    inTimeString,
  143.     LongDateRec &    outDateTime )
  144. {
  145.     Size                lengthUsed;
  146.     DateCacheRecord        theCache;
  147.     StringToDateStatus    stdStatus;
  148.  
  149.     ::InitDateCache( &theCache );
  150.  
  151.     stdStatus = ::StringToDate( (Ptr) &inDateString[1], inDateString[0],
  152.                 &theCache, &lengthUsed, &outDateTime );
  153.     stdStatus = ::StringToTime( (Ptr) &inTimeString[1], inTimeString[0],
  154.                 &theCache, &lengthUsed, &outDateTime );
  155. }
  156.  
  157.  
  158. // end of program
  159.